|
|
|
|
|
|
|
Understanding the Purpose of the File Operations Subsystem |
|
|
|
|
|
|
|
|
Handling the persistence of information to any source is a primary concern of every software application. Even serious computer and television video games have to save information about player scores to some media, whether it be hard disk or insertable memory cards. In Visual Basic, you need a handful of different classes to handle your application's own persistence needs. |
|
|
|
|
|
|
|
|
If you've been developing applications in Visual Basic for some time, you're probably familiar with the classic pair of file operation commands: |
|
|
|
|
|
|
|
|
Open FileName For Input As #FileNumber
'Grab some information from the file
Close #FileNumber |
|
|
|
|
|
|
|
|
Open FileName For Output As #FileNumber
'Persist some info into the file
Close #FileNumber |
|
|
|
|
|
|
|
|
The variable FileName can be any valid path and filename. By default, you normally save a file to the same path as that of your application. That is, the FileName variable could be set as |
|
|
|
|
|
|
|
|
FileName = App.Path & \SomeFile.txt |
|
|
|
|
|
|
|
|
The App object has a Path property that contains the name of the fully qualified folder in which your application resides. However, it doesn't contain the \ at the end, which is why the file, SomeFile.txt, is prefixed with the back slash. Figure 17.1 presents the primary pattern of classes you find in this subsystem. The classes in the class model are discussed later in this lesson. |
|
|
|
|
|
|
|
|
Because the classes of this subsystem use some of the traditional file operations at which Visual Basic excels, I cover these mechanisms in the following sections. The three types of file access operations Visual Basic supports are |
|
|
|
|
|
|
|
|
Sequential File Management |
|
|
|
|
|